﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using DAL.Linq.EntityMapper;

namespace DAL.Linq
{
    public class LinqDMDONVITINH_Dao : IDMDONVITINH_Dao
    {
        #region IDao<DMDONVITINHInfo,int> Members

        /// <summary>
        /// Gets a list of all DMDONVITINHs.
        /// </summary>
        /// <returns>List of DMDONVITINHs.</returns>
        public IList<DMDONVITINH> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a specific DMDONVITINH.
        /// </summary>
        /// <param name="maDonViTinh">Unique MaDonViTinh identifier.</param>
        /// <returns>DMDONVITINH.</returns>
        public DMDONVITINH GetById(int MaDonViTinh)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDMDONVITINH_Dao Members

        public bool DM_DonViTinh_Insert(string MaCode, string TenDonViTinh, bool IsUse, int CreateBy)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMDonViTinh_Insert (MaCode, TenDonViTinh, IsUse, CreateBy);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool DM_DonViTinh_Update(int MaDonViTinh, string TenDonViTinh, bool IsUse, int CreateBy, int ModifiedBy, DateTime ModifiedOn)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMDonViTinh_Update(MaDonViTinh,TenDonViTinh, IsUse, CreateBy, ModifiedBy, ModifiedOn);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }  
        }

        public bool DM_DonViTinh_Delete(int MaDonViTinh)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMDonViTinh_Delete(MaDonViTinh);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public IList<DMDONVITINH> GetAll_DMDonViTinh()
        {
            List<DMDONVITINH> lst = null;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    lst = db.sp_DMDonViTinh_GetAll().Select(p => Mapper.ToBusinessObject(p)).ToList();
                }
                catch { }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
            }
            return lst;
        }

        #endregion
    }
}
